<?php
class isp_vendor_invoice_model extends MY_Model {
	var $model = 'isp_vendor_invoice';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	ISP_VENDOR_INVOICE
					WHERE	(UPPER(kode_invoice) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kode_kontrak) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_invoice' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSON2()
	{
		$ls_sql	= "SELECT	*
					FROM	isp_vendor_kontrak
					WHERE	(UPPER(kode_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kode_vendor)'%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_vendor)'%".strtoupper(post('keyword'))."%'
							OR UPPER(harga) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_kontrak' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));

		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('isp_vendor_invoice', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_vendor_invoice', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kode_invoice){
		$result = $this->db->get_where('isp_vendor_invoice', array('kode_invoice' => $as_kode_invoice));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_invoice)
	{
		$result = $this->db->get_where('isp_vendor_invoice', array('kode_invoice' => $as_kode_invoice));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			//if(	intval($this->get_data("SELECT COUNT(1) FROM isp_vendor_invoice WHERE kode_invoice = '".$arr_rule['kode_invoice']."'"))>0)
			//{
			//	return $this->error_delete.' [id: '.$arr_rule['kode_invoice']."]<br />";
			//}else{
				$this->db->delete('isp_vendor_invoice', array('kode_invoice' => $arr_rule['kode_invoice']));
				return '';
			//}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>